Function.prototype.bindof = function(othis) { //添加bind函数
	var self = this;
	var args = Array.prototype.slice.call(arguments, 1);
	return function() {
		return self.apply(othis, args.concat(Array.prototype.slice.call(arguments)));
	}
};

function operateEvents(obj, evn, typ, fn) {
	typ ? (obj.attachEvent ? obj.attachEvent("on" + evn, fn) : obj.addEventListener(evn, fn)) : (obj
		.removeEventListener ? obj.removeEventListener(evn, fn) : obj.detachEvent("on" + evn, fn));
};

function stopEvents(e) {
	e && e.preventDefault ? e.preventDefault() : window.event.returnValue = false;
}

function stopBubble(e) {
	e && e.stopPropagation ? e.stopPropagation() : window.cancelBubble = true;
};

function timesFunc() {
	var tims = [];
	this.set = function(nam, fun, typ, tim) {
		var tf = false;
		if (typ) {
			for (var i = 0; i < tims.length; i++) {
				if (tims[i][0] == nam) {
					tf = true;
					tims[i] = [nam, fun, tim];
					break;
				};
			};
			if (tf) tims.push([nam, fun, tim]);
			if (this[nam]) clearInterval(this[nam]);
			this[nam] = setInterval(fun, tim);
		} else {
			if (this[nam]) clearTimeout(this[nam]);
			this[nam] = setTimeout(fun, tim);
		};
	};
	this.close = function(nam, typ) {
		if (typ) {
			if (this[nam]) {
				clearInterval(this[nam]);
				this[nam] = false;
			};
		} else {
			clearTimeout(this[nam]);
			this[nam] = null;
		};
	};
	this.showTims = function() {
		return tims;
	};
};
var otims = new timesFunc();

function exelm(elm) { //验证元素函数
	var obj;
	if ("string" == typeof elm) {
		obj = document.getElementById(elm);
		return obj && obj.tagName ? obj : false;
	} else {
		return elm && elm.tagName ? elm : false;
	};
};

function getstyle() { //获取样式函数
	var styUp, styLow, LowOrUp = null;
	this.upper = function(val) {
		val = val.match(/[a-zA-z]{1,}/g);
		if (val == null) return '';
		for (var i = 1; i < val.length; i++) val[i] = val[i].charAt(0).toUpperCase() + val[i].slice(1, val[i]
			.length);
		return val.join("");
	};
	this.lower = function(val) {
		val = val.match(/(^[a-z]+)|([A-Z]?[a-z]+)/g);
		if (!val) return false;
		for (var i = 0; i < val.length; i++) val[i] = val[i].toLowerCase();
		return val.join("-");
	};
	this.comstyle = function(obj, val, show) {
		if (!(typeof obj == "object") || !obj.tagName) return "0";
		if (LowOrUp) {
			styUp = window.getComputedStyle(obj, null)[this.upper(val)];
			if (styUp == undefined) {
				LowOrUp = false;
			};
			return styUp;
		} else if (LowOrUp == null) {
			styUp = window.getComputedStyle(obj, null)[this.upper(val)];
			styLow = window.getComputedStyle(obj, null)[this.lower(val)];
			if (styUp != undefined) {
				LowOrUp = true;
				return styUp;
			} else if (styLow != undefined) {
				LowOrUp = false;
				return styLow;
			} else {
				alert("Error Aruments!");
				return "Error Aruments!";
			};
		} else {
			styLow = window.getComputedStyle(obj, null)[this.lower(val)];
			if (styLow == undefined) {
				LowOrUp = true;
			};
			return styLow;
		};
	}
	this.curstyle = function(obj, val, show) {
		if (!(typeof obj == "object") || !obj.tagName) return "0";
		if (LowOrUp) {
			styUp = obj.currentStyle[this.upper(val)];
			if (styUp == undefined) {
				LowOrUp = false;
			};
			return styUp;
		} else if (LowOrUp == null) {
			styUp = obj.currentStyle[this.upper(val)];
			styLow = obj.currentStyle[this.lower(val)];;
			if (styUp != undefined) {
				LowOrUp = true;
				return styUp;
			} else if (styLow != undefined) {
				LowOrUp = false;
				return styLow;
			} else {
				alert("Error Aruments!");
				return "Error Aruments!";
			};
		} else {
			styLow = obj.currentStyle[this.lower(val)];
			if (styLow == undefined) {
				LowOrUp = true;
			};
			return styLow;
		};
	}
	this.get = (window.getComputedStyle ? this.comstyle : this.curstyle);
};

function DragAreaFunction(dragObj, mov, ctlTf) { //拖拽位置函数
	function initf(dragObj, mov) {
		var objtmp = new DragAreaFunction(dragObj, mov);
		return objtmp.obj ? objtmp : false;
	};
	this.init = initf;
	if (0 == arguments.length) return this
		.init; //if srguments is null. then return init(function) for create new Object

	if (!exelm(dragObj)) {
		alert("失败！dragObj is null/Error:stoping...");
		return false;
	};
	this.obj = exelm(dragObj);

	if (typeof(mov) == "object" && mov.obj) {
		this.oMove = mov;
	} else {
		alert("oMove is null/Error:create new oMove...");
		this.oMove = MoveAreaFunction()(dragObj);
	};
	this.closetim = "close" + new Date().getTime() + Math.random();

	this.demovef = function() {
		this.onbeforeReadyMove(1);
		otims.close(this.closetim, false);
	}
	this.demove = function(close) {
		close ? otims.close(this.closetim, false) : otims.set(this.closetim, this.demovef.bindof(this), false,
			1000);
	};

	this.onbeforeReadyMove = function(e) {
		if (ctlTf) return false;
		if (e != 1) {
			e = window.event || arguments[arguments.length - 1];
			stopEvents(e);
			stopBubble(e);
		};
		this.onready = this.onready ? false : true;
		this.obj.style.border = this.onready == true ? "1px solid #F00" : "1px solid " + this.oMove.border;

		this.move = false;
		this.onready ? this.demove() : this.demove(true);
	};
	this.onReadyMove = function(e) {
		e = window.event || arguments[arguments.length - 1];
		stopEvents(e);
		stopBubble(e);
		if (this.onready || ctlTf) {
			this.move = true;
			this.demove(true);
			this.defferX = e.clientX - this.oMove.obj.offsetLeft;
			this.defferY = e.clientY - this.oMove.obj.offsetTop;
			operateEvents(document, "mousemove", true, this.onMove.bindof(this));
		};
	};
	this.onMove = function(e) {
		e = window.event || arguments[arguments.length - 1];
		stopEvents(e);
		stopBubble(e);
		if (this.move) {
			this.oMove.move(e.clientX - this.defferX, e.clientY - this.defferY);
		};
	};
	this.end = function() {
		e = window.event || arguments[arguments.length - 1];
		stopEvents(e);
		stopBubble(e);
		if (this.onready || ctlTf) {
			this.move = false;
			operateEvents(document, "mousemove", false, this.onMove.bindof(this));
			this.demove();
		};
	};
	operateEvents(this.obj, "dblclick", true, this.onbeforeReadyMove.bindof(this, 12, 23));
	operateEvents(this.obj, "mousedown", true, this.onReadyMove.bindof(this));
	operateEvents(document, "mouseup", true, this.end.bindof(this));
};

function MoveAreaFunction(obj, box, gorun, nobd) { //移动位置函数
	function initf(obj, box, gorun) {
		var objtmp = new MoveAreaFunction(obj, box, gorun);
		return objtmp.obj ? objtmp : false;
	};
	this.x = 0;
	this.y = 0;
	this.init = initf;
	if (arguments.length == 0) {
		return this.init;
	}; //if srguments is null. then return init(function) for create new Object

	if (!exelm(obj)) {
		alert("失败！MoveAreaFunction:obj is null/Error!stoping...");
		this.obj = false;
		return false
	};
	this.obj = exelm(obj);

	if (typeof(box) == "function" && gorun == undefined) {
		this.goRun = box;
	} else if (exelm(box)) {
		this.box = (this.obj == exelm(box) ? (exelm(box).parentNode ? exelm(box).parentNode : null) : exelm(box));
	}; //else{alert("set Box: unknow Error:stoping...");gorun=false;};

	if (gorun) {
		this.goRun = gorun;
	};

	this.sty = new getstyle();

	if (this.sty.get(this.obj, "border-style") != 'none' && this.sty.get(this.obj, "borderColor")) {
		this.border = this.sty.get(this.obj, "borderColor");
	} else {
		this.border = this.sty.get(this.obj, "background-color");
		!this.border ? this.border = "black" : null;
	};
	if (!nobd) this.sty.get(this.obj, "border-width") == "0px" || this.sty.get(this.obj, "border-width") == "" ? this
		.obj.style.border = "1px solid " + this.border : null;
	if (this.box) this.limits = [0, 0, this.box.offsetWidth - this.obj.offsetWidth, this.box.offsetHeight - this.obj
		.offsetHeight
	];

	this.setGoRun = function(gorun) {
		this.goRun = gorun;
	};
	this.move = function(x, y) {
		if (this.limits) {
			this.x = (x < this.limits[0] ? this.limits[0] : (x > this.limits[2] ? this.limits[2] : x));
			this.y = (y < this.limits[1] ? this.limits[1] : (y > this.limits[3] ? this.limits[3] : y));
		};
		this.obj.style.left = this.x + "px";
		this.obj.style.top = this.y + "px";
		if (this.goRun) {
			this.goRun(this.x, this.y);
		};
	};
};

function runSizeTimer(obj) {
	if (!exelm(obj)) {
		return function() {
			alert("元素错误！Element is illegal!")
		};
	};
	obj = exelm(obj);

	this.reverse = 1;
	this.gotim = 0;
	this.precition = 1000000;
	this.speed = 5;
	this.opatf = false;

	this.helps = function() {
		alert(
			"  [opacity]:  set 0-100 _value\n  [position]:  change Left_set MaxPixle(+-)_value\n  [position_L]:  this too\n  [position_T]:  this too\n  [amplify]:  change left and amplify Elements_set LeftAndRightPixeleValue(+-)\n  [amplify_LT]:  this too\n  [amplify_LB]:  this too\n  [amplify_RT]:  this too\n  [amplify_RB]:  this too\n\nEND..."
			);
	};
	this.widthf = function(a, b, pct) {
		if (a)
			obj.style.width = parseInt(this.myX * pct) + "px";
		if (b)
			obj.style.height = parseInt(this.myY * pct) + "px";
	};
	this.opacityf = function(pct) {
		obj.style.filter = "alpha(Opacity:" + parseInt(this.myX * pct) + ")";
		obj.style.opacity = parseInt(pct * 10) / 10;
		if (obj.currentStyle) document.title = parseInt(this.myX * pct);
	};
	this.positionf = function(a, b, pct) {
		document.title = this.size;
		if (a)
			obj.style.left = parseInt(this.myX + this.size * pct) + "px";
		if (b)
			obj.style.top = parseInt(this.myY + this.size * pct * this.multiple) + "px";
	};
	this.amplifyf = function(a, b, pct) {
		if (a)
			obj.style.left = parseInt(this.myX + this.size * (1 - pct)) + "px";
		if (b)
			obj.style.top = parseInt(this.myY + this.size * (1 - pct) * this.multiple) + "px";
		obj.style.width = parseInt(this.myW * pct) + "px";
		obj.style.height = parseInt(this.myH * pct) + "px";
	}
	this.runaway = function() {
		this.percents += this.percenter * this.reverse;
		this.percenter = parseInt(this.percenter * this.quiken * 1000) / 1000;
		if (this.percents >= this.max) {
			this.percents = this.max;
			this.closetf = true;
		} else if (this.percents <= this.min) {
			this.percents = this.min;
			this.closetf = true;
		};
		switch (this.type) {
			case "opacity":
				this.opacityf(this.percents / this.precition);
				break;
			case "position":
				this.positionf(1, 1, this.percents / this.precition);
				break;
			case "position_L":
				this.positionf(1, 0, this.percents / this.precition);
				break;
			case "position_T":
				this.positionf(0, 1, this.percents / this.precition);
				break;
			case "amplify":
				this.amplifyf(1, 1, this.percents / this.precition);
				break;
			case "amplify_LT":
				this.amplifyf(0, 0, this.percents / this.precition);
				break;
			case "amplify_LB":
				this.amplifyf(0, 1, this.percents / this.precition);
				break;
			case "amplify_RT":
				this.amplifyf(1, 0, this.percents / this.precition);
				break;
			case "amplify_RB":
				this.amplifyf(1, 1, this.percents / this.precition);
				break;
			default:
				return false;
		};
		if (this.type.search(/position/) + 1 && this.opatf) {
			this.opacityf(1 - this.percents / this.precition);
		} else if (this.type != "opacity" && this.opatf) {
			this.opacityf(this.percents / this.precition);
		};
		if (this.closetf) {
			clearInterval(this.gotim);
			return false;
		};
	};
	this.togo = function(tims, opa_tf, quik) {
		this.percenter = parseInt((this.speed / tims) * this.precition);
		this.reverse *= -1;
		this.closetf = false;
		this.opatf = opa_tf;
		if (quik) {
			this.quiken = (quik < 0.9835 ? 0.9835 : quik > 1.05 ? 1.05 : quik);
		} else {
			this.quiken = 1;
		};
		switch (this.type) {
			case "opacity":
				this.nowvalue = stys.get(obj, "opacity");
				this.datumvalue = obj.currentStyle ? 1 : 1;
				break;
			case "position":
				this.nowvalue = getlefttop(obj, "left") - this.myX;
				this.datumvalue = this.size;
				break;
			case "position_L":
				this.nowvalue = getlefttop(obj, "left") - this.myX;
				this.datumvalue = this.size;
				break;
			case "position_T":
				this.nowvalue = getlefttop(obj, "top") - this.myY;
				this.datumvalue = this.size;
				break;
			case "amplify":
				this.nowvalue = obj.offsetWidth;
				this.datumvalue = this.myW;
				break;
			case "amplify_LT":
				this.nowvalue = obj.offsetWidth;
				this.datumvalue = this.myW;
				break;
			case "amplify_LB":
				this.nowvalue = obj.offsetWidth;
				this.datumvalue = this.myW;
				break;
			case "amplify_RT":
				this.nowvalue = obj.offsetWidth;
				this.datumvalue = this.myW;
				break;
			case "amplify_RB":
				this.nowvalue = obj.offsetWidth;
				this.datumvalue = this.myW;
				break;
			default:
				return false;
		};
		this.percents = parseInt(this.datumvalue != 0 ? this.nowvalue / this.datumvalue * this.precition : 0);
		clearInterval(this.gotim);
		this.gotim = setInterval(this.runaway.bindof(this), this.speed);
	};
	this.set = function(typ, mi, ma, siz) {
		if (arguments.length == 0) {
			this.helps();
		}
		this.min = (mi < 0 ? 0 : mi > ma ? ma / 100 * this.precition : mi / 100 * this.precition);
		this.max = (ma > 100 ? 1 * this.precition : ma < this.min / this.precition * 100 ? this.min / this
			.precition * 100 : ma / 100 * this.precition);
		this.type = typ;
		if (typeof siz == "string") {
			if (siz.search(/all/) + 1) {
				this.size = obj.offsetWidth;
			} else {
				this.size = siz.search(/half/) + 1 ? obj.offsetWidth / 2 : siz.search(/\-?[0-9]{1,4}px/) + 1 ? eval(
					siz.replace(/[^0-9]/g, '')) : siz.search(/^\-?[0-9]{1,4}$/) + 1 ? eval(siz.replace(
					/[^0-9]/g, '')) : 3;
			};
			siz.search(/\-/) + 1 ? this.size *= -1 : null;
		} else {
			this.size = parseInt(siz) + 1 ? siz : 3;
		};
		if (this.size && this.type.search(/(position)|(amplify)/) + 1) {
			this.myX = getlefttop(obj, "left");
			this.myW = obj.offsetWidth;
			this.myY = getlefttop(obj, "top");
			this.myH = obj.offsetHeight;
			this.multiple = this.myH / this.myW;
			this.type.search(/amplify/) ? this.reverse *= -1 : null;
		} else if ("opacity" == this.type) {
			this.myX = (obj.currentStyle ? 100 : 1);
		};
	}
};

function getlefttop(obj, str) {
	return parseInt(stys.get(obj, str));
};

function amplifyReduce(elm, filter) { //自动缩放函数 带淡入淡出
	function init(elm, filter) {
		var objtmp = new amplifyReduce(elm, filter);
		return !objtmp.obj ? false : objtmp;
	};
	if (!arguments.length) return init;

	if (!exelm(elm)) {
		alert(exelm(elm) + " no Found this Element!");
		return false;
	};
	this.obj = exelm(elm);
	if (filter) this.Filter = true;
	this.toInout = 1;
	this.setwidth = this.obj.offsetWidth;
	this.setheight = this.obj.offsetHeight;
	this.widthMultiple = parseInt(this.setwidth / this.setheight * 100000) / 100000;
	this.tims = 5;
	this.chgsize = function(x, y, opa) {
		this.obj.style.width = parseInt(x) + "px";
		this.obj.style.height = parseInt(y) + "px";
		if (this.Filter) {
			this.obj.style.opacity = opa / 100;
			this.obj.style.filter = "alpha(Opacity:" + opa + ")";
		};
		//document.title=show+"_"+x+":"+y+":"+opa;
	}
	this.toInAndOut = function() {
		this.X += this.toInout * this.runwidth;
		this.Y = this.X / this.widthMultiple;
		if (this.X <= 0 || this.X >= this.setwidth) {
			this.X = this.setwidth * (this.toInout + 1) / 2;
			this.Y = this.setheight * (this.toInout + 1) / 2;
			this.chgsize(this.X, this.Y, 100 * (this.toInout + 1) / 2, true);
			clearInterval(this.tim);
			return false;
		};
		this.chgsize(this.X, this.Y, parseInt(this.X / this.setwidth * 100));
		document.getElementById("test2").innerHTML = new Date().toLocaleTimeString();
	}
	this.go = function(tims, elms) {
		if (!tims) tims = 1;
		this.runwidth = this.setwidth / (tims / this.tims);
		this.toInout *= -1;
		this.X = this.obj.offsetWidth;
		clearInterval(this.tim);
		this.tim = setInterval(this.toInAndOut.bind(this), this.tims);
	}
};